package com.cn.controller.dz;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.cn.controller.BaseServlet;
import com.cn.entity.User_entity;
import com.cn.service.RegisterContrl;

@WebServlet("/register")
public class Register extends BaseServlet {
	private User_entity user;
	private RegisterContrl rc;
	public Register(){
		user = new User_entity();
		rc = new RegisterContrl();
	}
	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
		forward("dz_/register");
	}
	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
			String name = req.getParameter("re_name");//获取提交的名字
			String phon = req.getParameter("re_phon");//获取提交的电话
			String pw = req.getParameter("re_pw");//获取提交的密码
			String yhm = req.getParameter("re_yhm");//获取提交的优惠码
			req.getSession().removeAttribute("yzm");//移除使用过的yzm
			//将信息写入用户对象中
			user.setName(name);
			user.setPhone(phon);
			user.setPassword(pw);
			int row = rc.upUser(user);
			if(row != -1){
				System.out.println("ok");
				forward("dz_/ok");
			}else{
				System.out.println("no");
			}
	}
}
